package com.pureut.quality.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.utils.bean.BeanUtils;

import com.pureut.quality.domain.MaterialCoding;
import com.pureut.quality.domain.dto.MaterialCodingMqDto;
import com.pureut.quality.mapper.MaterialCodingMapper;
import com.pureut.quality.service.IMaterialCodingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 类别实现类
 * @Param
 * @Date 22-11-24
 * @Author hl
 **/
@Service
public class MaterialCodingServiceImpl extends ServiceImpl<MaterialCodingMapper, MaterialCoding> implements IMaterialCodingService {

    @Resource
    MaterialCodingMapper materialCodingMapper;

    /**
     * 新增
     *
     * @param materialCodingMqDto
     */
    @Override
    public void insertMaterialCoding(MaterialCodingMqDto materialCodingMqDto) {
        if (materialCodingMqDto.getCodingCode() != null) {
            MaterialCoding materialCoding1 = materialCodingMapper.selectOne(new QueryWrapper<MaterialCoding>().lambda().eq(MaterialCoding::getCodingCode, materialCodingMqDto.getCodingCode()));
            if (materialCoding1 == null) {
                MaterialCoding materialCoding = new MaterialCoding();
                BeanUtils.copyProperties(materialCodingMqDto, materialCoding);
                boolean save = save(materialCoding);
                System.out.println(save);
            }
        }
    }

    /**
     * 修改
     *
     * @param materialCodingMqDto
     */
    @Override
    public void updateMaterialCoding(MaterialCodingMqDto materialCodingMqDto) {
        MaterialCoding materialCoding = materialCodingMapper.selectOne(new QueryWrapper<MaterialCoding>().lambda().eq(MaterialCoding::getCodingCode, materialCodingMqDto.getCodingCode()));
        if (materialCoding != null) {
            BeanUtils.copyProperties(materialCodingMqDto, materialCoding);
            boolean b = updateById(materialCoding);
            System.out.println(b);
        }

    }

    /**
     * 删除
     *
     * @param materialCodingMqDto
     */
    @Override
    public void deleteMaterialCoding(MaterialCodingMqDto materialCodingMqDto) {
        if (materialCodingMqDto.getCodingCode() != null) {
            MaterialCoding materialCoding = materialCodingMapper.selectOne(new QueryWrapper<MaterialCoding>().lambda().eq(MaterialCoding::getCodingCode, materialCodingMqDto.getCodingCode()));
            if (materialCoding != null) {
                removeById(materialCoding);
            }
        }

    }
}
